<%@ page import="com.ld.manageBook.service.BookService" %>
<%@ page import="com.ld.manageBook.service.impl.BookServiceImpl" %>
<%@ page import="com.ld.manageBook.bean.Books" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-02
  Time: 10:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加图书结果</title>
</head>
<body>
<%!
    private BookService bookService = new BookServiceImpl();
%>
<%
    String name = request.getParameter("name");
	String author = request.getParameter("author");
	double price = Double.parseDouble(request.getParameter("price"));
	String remarks = request.getParameter("remarks");
	Integer number = Integer.parseInt(request.getParameter("number"));
    Books book = new Books();
	book.setName(name);
	book.setAuthor(author);
	book.setPrice(price);
	book.setRemarks(remarks);
	book.setNumber(number);
    Books bookByName = bookService.getBookByName(name);
	if(bookByName != null){
		out.println("该书籍已经存在");
    }else {
        int i = bookService.addBook(book);
        if (i == 1) {
            out.println("<h1>添加成功</h1>");
        } else {
            out.println("<h1>添加失败,请稍后重试</h1>");
        }
    }
    out.println("<a href='/home/manageBook.jsp'>返回图书管理页</a>");
%>
</body>
</html>
